package rabbit.flt.plugins.springmvc.matcher;

import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import rabbit.flt.plugins.common.matcher.ConstructorMatcher;

import static net.bytebuddy.matcher.ElementMatchers.*;

public class ControllerConstructorMatcher implements ConstructorMatcher {

    @Override
    public ElementMatcher.Junction<TypeDescription> classMatcher() {
        String restController = "org.springframework.web.bind.annotation.RestController";
        String controller = "org.springframework.stereotype.Controller";
        ElementMatcher.Junction<TypeDescription> isController = hasAnnotation(annotationType(named(restController))
                .or(annotationType(named(controller))));
        return not(isInterface()).and(isController)
                // 不增强自带的Component
                .and(not(nameStartsWith("org.springframework")));
    }

    @Override
    public ElementMatcher.Junction methodMatcher(TypeDescription typeDescription) {
        return any();
    }

    @Override
    public String getPluginClassName() {
        return "rabbit.flt.plugins.springmvc.plugin.PathResolvePlugin";
    }
}
